package com.rabbiter.oes.serviceimpl;

import com.rabbiter.oes.entity.Banks;
import com.rabbiter.oes.mapper.BanksMapper;
import com.rabbiter.oes.service.BanksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BanksServiceImpl implements BanksService {

    @Autowired
    private BanksMapper banksMapper;

    @Override
    public List<Banks> listAllBanks() {
        return banksMapper.selectAll();
    }

    @Override
    public List<Banks> listBanksBySubject(String subject) {
        return banksMapper.selectBySubjectLike(subject);
    }

    public void addIfNotExists(String subject) {
        if (subject == null || subject.trim().isEmpty()) {
            return;
        }
        subject = subject.trim();

        Integer exists = banksMapper.findBySubject(subject);
        if (exists == null || exists == 0) {
            banksMapper.save(subject);
        }
    }
}